package com.yidu.hbatsft.action;

import com.yidu.hbatsft.domain.AtsBaseSport;
import com.yidu.hbatsft.domain.AtsEmpExpert;
import com.yidu.hbatsft.domain.AtsEmpExpertVo;
import com.yidu.hbatsft.domain.AtsEmpLeader;
import com.yidu.hbatsft.service.AtsEmpExpertService;
import com.yidu.utils.Message;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 专家控制器
 */
@Controller
@RequestMapping("AtsEmpExpert")
public class AtsEmpExpertContller {

    @Resource
    AtsEmpExpertService aees;

    @RequestMapping("findAll")
    @ResponseBody
    public Map<String,Object> findAll(@RequestParam("page") Integer pageNum, @RequestParam("limit") Integer pageSize,String expertName){

        Map<String,Object> map = new HashMap<String,Object>();

        List<AtsEmpExpert> ats = aees.findAll(pageNum,pageSize,expertName);

        int cout = aees.findCout();

        map.put("code",0);
        map.put("msg","");
        map.put("count",cout);
        map.put("data",ats);

        return map;
    }

    @RequestMapping("finAlls")
    @ResponseBody
    public List<AtsEmpExpert> finAlls(){
        System.out.println("进来了。。。。。。。。。。。。。");
        List<AtsEmpExpert> list =aees.findAlls();
        return list;
    }

    @RequestMapping("findById")
    @ResponseBody
    public AtsEmpExpertVo findById(Integer id){

        System.out.println("=====================进入");
        AtsEmpExpertVo aee = aees.findById(id);
        System.err.println(aee.getUsName());
        return  aee;
    }

    /**
     * 修改或新增专家信息
     * @param ate   某个专家的信息
     * @return
     */
    @RequestMapping("updateExpet")
    @ResponseBody
    public Message updateExpet(AtsEmpExpertVo ate, MultipartFile file){
        Message msg = new Message();

        int cout = aees.upOrInertExpertDate(ate,file);
        if(cout>0){
            msg.setMsg("操作成功");
        }else{
            msg.setMsg("操作异常");
        }
        return  msg;
    }

    @RequestMapping("deleteExpertDate")
    @ResponseBody
    public Message deleteExpertDate(Integer id){
        Message msg = new Message();

       int cout = aees.deleteExpertDate(id);
       if(cout >0){
           msg.setMsg("操作成功");
       }else{
           msg.setMsg("操作失败");
       }
        return msg;
    }

    /**
     * 加载专业项
     * @return
     */
    @RequestMapping("loadSprot")
    @ResponseBody
    public List<AtsBaseSport> loadSprot(){

        return aees.loadSprot();
    }

    @RequestMapping("deleteCoachDates")
    @ResponseBody
    public Message deleteCoachDates(String ids){
        Message msg = new Message();
        String id[] = ids.split(",");
        int cout =0;
        for (int i=0;i<id.length;i++){
            Integer e = Integer.valueOf(id[i]);
            cout = aees.deleteExpertDate(e);
        }
        if(cout>0){
            msg.setMsg("删除成功");
        }else{
            msg.setMsg("删除异常，请刷新重试~");
        }
        return  msg;
    }
}
